package com.geez.bbl.util;

import java.io.File;

/**
 * User: biniam.gebremichael
 * Date: Jul 13, 2010
 */
public class ProjectResources {




    public static File getResourceFile( String... path) {
     return chainDirs(getResourceDir(), path);
 }


       public static File getResourceDir() {
        return chainDirs(getProjectRoot(), "src", "resource");
    }


    public static File getProjectRoot() {
        System.out.println("hi");
        File file = new File(System.getProperty("user.dir"));
        if(ProjectResources.class.getResource("/")!=null&& ProjectResources.class.getResource("/").getFile()!=null){
            file = new File(ProjectResources.class.getResource("/").getFile());
        }
        System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
        while (!file.getName().endsWith("target")) {
            file = file.getParentFile();
        }
        return file.getParentFile();
    }

     public static File chainDirs(File parent, String... dirs) {
        File result = parent;
        for (String s : dirs) {
            result = new File(result, s);
        }
        return result;
    }
}
